﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;

namespace Biuro.Formy
{
    public delegate void DodawanieKraju();
    public delegate void DodanieTransportu();
    public partial class AddEditKurort : Form
    {
        public event DodawanieKraju DodajKraj;
        public event DodanieTransportu DodajTransport;
        public string Nazwa
        {
            get { return tbNazwa.Text; }
            set { tbNazwa.Text = value; }
        }
        ArrayList kraje;

        public ArrayList Kraje
        {
            get { return kraje; }
            set 
            { 
                kraje = value;
                cbKraje.DataSource = null;
                cbKraje.DisplayMember = "Nazwa";
                cbKraje.ValueMember = "Liczba";
                cbKraje.DataSource = kraje;
            }
        }
        public int WybranyKraj
        {
            get { return Int32.Parse(cbKraje.SelectedValue.ToString()); }
        }
        public string Opis
        {
            get { return tbOpis.Text; }
            set { tbOpis.Text = value; }
        }
        public AddEditKurort()
        {
            InitializeComponent();
        }

        private void lbDodajKraj_Click(object sender, EventArgs e)
        {
            if (DodajKraj != null)
                DodajKraj();
        }

        private void lbDodajTransport_Click(object sender, EventArgs e)
        {
            if (DodajTransport != null)
                DodajTransport();
        }

        private void AddEditKurort_Load(object sender, EventArgs e)
        {
            Reset();
            cbKraje.DataSource = null;
            cbKraje.DisplayMember = "Nazwa";
            cbKraje.ValueMember = "Liczba";
            cbKraje.DataSource = kraje;
        }

        private void btDodaj_Click(object sender, EventArgs e)
        {
            if (!Regex.IsMatch(tbNazwa.Text.ToLower(), @"\b\p{L}{2,25}\b"))
            {
                tbNazwa.BackColor = Color.Red;
            }
            else
            {
                tbNazwa.BackColor = Color.White;
                this.DialogResult = DialogResult.OK;
            }
        }
        public void Reset()
        {
            foreach (TextBox t in this.Controls.OfType<TextBox>().ToArray())
                t.Text = "";
        }

        private void AddEditKurort_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Drawing2D.LinearGradientBrush basebackground;
            basebackground = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, ClientSize.Height), Color.White, Color.LightGray);
            e.Graphics.FillRectangle(basebackground,ClientRectangle);
        }

    }
}
